$('#link').on('click', '.item', function () {
    var id = $(this).attr('id');
    location.href = './book.html?id=' + id;
})

$('#new-book').on('click', '.item', function () {
    var id = $(this).attr('id');
    location.href = './book.html?id=' + id;
})

$('#best').on('click', '.item', function () {
    var id = $(this).attr('id');
    location.href = './book.html?id=' + id;
})

$('#author').on('click', '.item', function () {
    var id = $(this).attr('id');
    location.href = './people1.html?id=' + id;
})

$('#award').on('click', '.item', function () {
    var id = $(this).attr('id');
    location.href = './book.html?id=' + id;
})

var likeObj = {
    //获取列表数据
    getList() {
        var url = 'http://localhost:3001/likeList';
        axios.get(url).then(function (res) {
            console.log(res.data);
            likeObj.render(res.data);
        }).catch(function (err) {
            console.log('请求失败', err);
        })
    },
    //渲染页面
    render(list) {
        var htmlStr = '';
        list.forEach(function (item) {
            htmlStr += `
                <li id="${item.id}" class="item flex fdc aic mt-5">
                    <img src="${item.imgUrl}" alt="">
                    <span>${item.name}</span>
                </li>
                `;
        })
        $('#link').html(htmlStr);
    }
}
likeObj.getList();

// 渲染新书驾到部分
var newBookObj = {
    // 获取新书数据
    getList() {
        var url = 'http://localhost:3001/newBookList';
        axios.get(url).then(function (res) {
            console.log(res.data);
            newBookObj.render(res.data);
        }).catch(function (err) {
            console.log('请求失败', err);
        })
    },
    // 渲染新书页面
    render(list) {
        var htmlStr = '';
        list.forEach(function (item) {
            htmlStr += `
        <li class="item flex fdc aic pr-10 f14" data-id="10" id=${item.id}>
            <img src="${item.imgUrl}" alt="">
            <span>${item.name}</span>
        </li>
        `;
        })
        $('.new-book ul').html(htmlStr);
    }
}
newBookObj.getList();

// 渲染近期畅销部分
var bestObj = {
    // 获取畅销书数据
    getList() {
        var url = 'http://localhost:3001/bestList';
        axios.get(url).then(function (res) {
            console.log(res.data);
            bestObj.render(res.data);
        }).catch(function (err) {
            console.log('请求失败', err);
        })
    },
    // 渲染畅销书页面
    render(list) {
        var htmlStr = '';
        list.forEach(function (item) {
            htmlStr += `
        <li class="item flex fdc aic pr-10 f14" data-id="10" id=${item.id}>
            <img src="${item.imgUrl}" alt="">
            <span>${item.name}</span>
        </li>
        `;
        })
        $('.best ul').html(htmlStr);
    }
}
bestObj.getList();

var authorObj = {
    // 获取作者列表数据
    getList() {
        var url = 'http://localhost:3001/people1List';
        axios.get(url).then(function (res) {
            console.log(res.data);
            authorObj.render(res.data); // 修改这里，确保使用正确的对象调用render方法
        }).catch(function (err) {
            console.error('请求失败', err);
        });
    },
    // 渲染作者列表页面
    render(list) {
        var htmlStr = '';
        list.forEach(function (item) {
            htmlStr += `
            <li class="item flex fdc aic pr-10" id="${item.id}">
                <img src="${item.imageUrl}" alt="">
                <span>${item.name}</span>
            </li>
            `;
        });
        $('.author ul').html(htmlStr); // 确保HTML中有对应的元素
    }
};

// 调用getList方法获取并渲染作者列表
authorObj.getList();